# -*- coding: utf-8 -*-
# Create your views here.

from icpcweb.models import *
from django.http import HttpResponse
from django.template import Context, loader

def main_page(request):
    page_title = "Sogang acm icpc Main page"
    menu_dict = { "Member list":"member_list", "Board":"board", 
    "Road map":"road_map", "Login / Register":"login_register" }
    
    tpl = loader.get_template('main.html')
    ctx = Context({
        'page_title':page_title,
        'menu_dict':menu_dict,
        })
    
    return HttpResponse(tpl.render(ctx))
    
def member_list(request):
    page_title = "Sogang ACM ICPC Member list"
    
    #entries = User.objects.all()
    ###########################################
    entry = User()
    entry.job = "Student"
    entry.name = "Baek seung hwan"
    entry.email = "safariworldcom@gmail.com"
    entry.cardinal_number = "09"
    
    entries = [entry,]
    ###########################################
    
    

    tpl = loader.get_template('member_list.html')
    ctx = Context({
        'page_title':page_title,
        'entries':entries,
        })
    # add 'entries' into ctx
    
    return HttpResponse(tpl.render(ctx))
    
def road_map(request):
    
    page_title = "Road map"
    
    tpl = loader.get_template('road_map.html')
    ctx = Context({
        'page_title':page_title,
        })
    # add 'entries' into ctx
    
    return HttpResponse(tpl.render(ctx))
    
def register_page(request):
    page_title = "Register"

    tpl = loader.get_template('register.html')
    ctx = Context({
                   'page_title':page_title,
                   })

    return HttpResponse(tpl.render(ctx))

def login(request):

    return HttpReponse()

def register(request):

    username = request.POST.get('username')
    password = request.POST.get('password')


    tpl = loader.get_template('main.html')
    '''
    ctx = Context({
                   'page_title':page_title,
                   })
                   '''
    #return HttpResponse(tpl.render(ctx))
    output = '''
        <html>
            <head><title>%s</title></head>
                <body>
                    <h1>%s</h1>
                    <p>%s</p>

                </body>
        </html>
    ''' % (
        'Sogang ACM ICPC',
        'Register Success?!, We need to work on models.',
        'Hello',
        )
    return HttpResponse(output)

def login_register(request):
    
    page_title = "Login/Register"
    register_url = "register_page"
    
    tpl = loader.get_template('login_register.html')
    ctx = Context({
        'page_title':page_title,
        'register_url':register_url,
        })
    # add 'entries' into ctx
    
    return HttpResponse(tpl.render(ctx))
